package com.yupi.yupicturebackend.api.baidu.imageRecognition.sub;

import org.apache.commons.codec.digest.DigestUtils;
import java.util.UUID;

/**
 * 百度图片识别签名生成器
 */
public class BaiduSignGenerator {

    // 从JS逆向获取的固定secret
    private static final String SECRET = "d3a9125fb75915a8f40375d1de76514a";

    public static AuthInfo generateAuth() {
        long timestamp = System.currentTimeMillis() / 1000;
        String nonce = UUID.randomUUID().toString().replace("-", "");
        String sign = DigestUtils.md5Hex(timestamp + nonce + SECRET);

        return new AuthInfo(
                UUID.randomUUID().toString(), // Demo-Id
                String.valueOf(timestamp),   // Demo-TimeStamp
                sign                        // Demo-Authentication
        );
    }

    public static class AuthInfo {
        public final String demoId;
        public final String timestamp;
        public final String authentication;

        public AuthInfo(String demoId, String timestamp, String authentication) {
            this.demoId = demoId;
            this.timestamp = timestamp;
            this.authentication = authentication;
        }
    }
}